import {GetTravels, GetUserTravels, UserLottery, UserTodayLotteryCount} from "../../model/travels"

Page({
        data: {
            travelsList: [],
            startMaskShow: false,
            last_count: 0
        },
        onLoad: function (options) {
        },
        onShow() {
            this.getTravels()
            this.getUserLottery()
        },
        getTravels() {
            GetUserTravels().then(res => {
                res.pop()
                this.setData({
                    travelsList: res
                })
            })
        },
        getLottery() {
            UserLottery().then(res => {
                this.setData({
                    last_count: res.count - res.used_count
                })
            })
        },
        getUserLottery() {
            UserTodayLotteryCount().then(res => {
                if (res.count == 0) {
                    this.setData({
                        startMaskShow: true
                    })
                } else {
                    this.getLottery()
                }
            })
        },
        onItemTap(e) {
            const item = e.currentTarget.dataset.item
            console.log(item)
            wx.navigateTo({
                url: `/pages/walkDetail/index?category=${item.category}`
            })
        },
        onRuleTap() {
            wx.navigateTo({
                url: '/pages/travelRule/index'
            })
        },
        onCloseMask() {
            this.setData({
                startMaskShow: false
            })
        },
        onLotteryClick() {
            setTimeout(() => {
                this.setData({
                    startMaskShow: false
                })
                this.getUserLottery()
            }, 1500)
        }
    }
);
